//
//  YGFoodTimeSelectView.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/4/24.
//

#import "YGFoodTimeSelectView.h"

@interface YGFoodTimeSelectView ()
@property (nonatomic, strong) UILabel  *timeLabel;
@property (nonatomic, strong) UIImageView  *dateIcon;

@end
@implementation YGFoodTimeSelectView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        
        self.layer.borderColor = UIColorFromRGB(0x333333).CGColor;
        self.layer.borderWidth = 0.5;
        self.clipsToBounds = YES;
        self.layer.cornerRadius = 4;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAction)];
        [self addGestureRecognizer:tap];
    }
    return self;
}

- (void)initView{
    [self addSubview:self.timeLabel];
    [self addSubview:self.dateIcon];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).mas_offset(10);
        make.top.bottom.mas_equalTo(self);
    }];
    
    [self.dateIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.mas_right).offset(-3);
        make.width.height.mas_equalTo(13);
        make.centerY.mas_equalTo(self.timeLabel.mas_centerY);
    }];
}

- (void)setDate:(NSString *)date{
    self.timeLabel.text = date;
}

- (void)clickAction{
    if (self.ClickCallBlock) {
        self.ClickCallBlock();
    }
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.font = [UIFont systemFontOfSize:12];
        _timeLabel.textColor = UIColorFromRGB(0x333333);
    }
    return _timeLabel;
}

- (UIImageView *)dateIcon{
    if (!_dateIcon) {
        _dateIcon = [[UIImageView alloc] init];
        _dateIcon.image = [UIImage imageNamed:@"calendar"];
    }
    return _dateIcon;
}
@end
